package com.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.health.pojo.Setmeal;
import com.health.service.SetMealService;
import com.health.utils.QiNiuUtil;
import com.health.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/setMeal")
public class SetMealController {

    @Reference
    private SetMealService setMealService;

    /**
     * 查询套餐基本信息
     */
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Integer id) {
        Setmeal setmeal = setMealService.findById(id);

        //封装套餐列表与图片所在域名
        Map<String, Object> map = new HashMap<>();
        map.put("setmeal", setmeal);
        map.put("domain", QiNiuUtil.DOMAIN);

        return new Result(true, "查询套餐基本信息成功", map);
    }

    /**
     * 查询套餐详情
     */
    @GetMapping("/findDetail/{id}")
    public Result findDetail(@PathVariable Integer id) {
        Setmeal setmeal = setMealService.findDetail(id);

        //封装套餐列表与图片所在域名
        Map<String, Object> map = new HashMap<>();
        map.put("setmeal", setmeal);
        map.put("domain", QiNiuUtil.DOMAIN);

        return new Result(true, "查询套餐详情成功", map);
    }

    /**
     * 查询所有套餐
     */
    @GetMapping("/findAll")
    public Result findAll() {
        List<Setmeal> setmealList = setMealService.findAll();

        //封装套餐列表与图片所在域名
        Map<String, Object> map = new HashMap<>();
        map.put("list", setmealList);
        map.put("domain", QiNiuUtil.DOMAIN);

        return new Result(true, "查询所有套餐成功", map);
    }
}
